/**
 * xxx 模型
 */

'use strict';

var mongoose = require('../mongo_conn.js');
var Schema = mongoose.Schema;
var ObjectId = Schema.Types.ObjectId;

// create a schema
var ModelSchema = new Schema({
	name: {
		type: String,
		require: true,
	},
	description: String,
	isRoot: {
		type: Number,
		default: 0
	},
	path: [String],
	vendors: [String],
	createdAt: {
		type: Date,
		default: Date.now
	},
	updatedAt: {
		type: Date,
		default: Date.now
	}
});

ModelSchema.pre('save', function(next) {
	if (!this.createdAt) {
		this.createdAt = new Date();
	}
	next();
});


ModelSchema.statics.findAndModify = function(query, sort, doc, options, callback) {
	return this.collection.findAndModify(query, sort, doc, options, callback);
};

// 指定collection name，默认是复数
var orgnization = mongoose.model('orgnization', ModelSchema, 'orgnization');
exports = module.exports = orgnization;